package org.tis.tools.abf.module.sys.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tis.tools.abf.module.sys.entity.SysDict;
import org.tis.tools.abf.module.sys.service.ISysDictService;
import org.tis.tools.core.web.controller.BaseController;
import org.tis.tools.core.web.vo.SmartPage;
import org.tis.tools.model.common.ResultVO;

import javax.validation.constraints.NotBlank;

/**
 * 对外提供查询业务字典
 *
 * Created by chenchao
 * Created on 2018/9/5 17:48
 */
@RestController
@RequestMapping("/v1/api/sysDicts")
@Validated
@Api(description = "对外业务字典")
@Slf4j
public class SysDictApiController extends BaseController<SysDict> {

    @Autowired
    private ISysDictService sysDictService;

    @ApiOperation(value = "根据业务字典key值查询子字典和字典项",notes = "传入dictKey为参数")
    @GetMapping("/{dictKey}/dictItems")
    public ResultVO queryDictSon(@PathVariable @NotBlank(message = "业务字典不能为空") @ApiParam(value = "dictKey",name = "传入业务字典key值作为查询条件",required = true) String dictKey){
        return ResultVO.success("查询成功",sysDictService.queryDictSon(dictKey));
    }

    @ApiOperation(value = "查询业务字典",notes = "传入字典名称,字典类型,业务字典作为参数")
    @PostMapping("/getSysDict")
    public ResultVO getSysDict(@RequestBody @Validated @ApiParam(value = "page",name = "分页信息", required =
            true) SmartPage<SysDict> page){
        return ResultVO.success("查询成功",sysDictService.getSysDict(page.getPageObj(),page.getConditionWrapper()));
    }

//    @ApiOperation(value = "查询业务字典树", notes = "传入业务字典GUID作为参数")
//    @PostMapping("/tree/{guid}")
//    public ResultVO tree(@PathVariable @NotBlank(message = "guid不能为空") @ApiParam(value = "guid",name = "业务字典的GUID", required = true) String guid){
//        SysDict sysDict = sysDictService.selectById(guid);
//        if (sysDict == null){
//            return ResultVO.error("404", "找不到对应记录或已经被删除！");
//        }
//        return ResultVO.success("查询成功",sysDictService.queryDictTree(guid));
//    }

}
